package cn.yr.service.manage.system;

import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.StrUtil;
import cn.yr.common.manager.TokenManager;
import cn.yr.common.util.AjaxResult;
import cn.yr.domain.entity.SysUser;
import cn.yr.service.manage.ISysUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class SysLoginService {

	@Resource
	private ISysUserService userService;

	public String login(String username,String password,String code){
		SysUser sysUser = userService.selectUserByUserName(username);
		if(ObjectUtil.isEmpty(sysUser)){
			AjaxResult.error("找不到该用户");
			return null;
		}
		if(!StrUtil.equals(password,sysUser.getPassword())){
			AjaxResult.error("密码错误");
			return null;
		}
		return TokenManager.createJWT(sysUser.getUserId().toString());
	}
}
